<script language="javascript" type="text/javascript">

// this is installing an event listener for events from checktab.js 
// if request.activate=true - we have a google docs url
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
 		if(request.activate=="true")	
		{
			// make clicktopost icon visible in the omnibox 
			chrome.pageAction.show(sender.tab.id);
		}
		else
		{	
			// make clicktopost icon invisible in the omnibox 
			chrome.pageAction.hide(sender.tab.id);
		}
    sendResponse({}); // send null response back to confirm
  });


  
  // this is installing an event listener for when the clicktopost icon is clicked
chrome.pageAction.onClicked.addListener(function( tab) {

	// get the url of the tab
	var tablink = tab.url;

	if(tablink.indexOf("id=")>0)
	{
		l=tablink.indexOf("id=");
		try
		{
		
			var docid=tablink.substr(l+3).split("&")[0];
			var tabsrc="https://clicktopost.appspot.com/Clicktopost.html?docid="+docid;
			chrome.tabs.create({url:tabsrc});
			
			
			
		}
		catch(err)
		{
			alert("Could not get google document id");
		}
	}
	
	else if(tablink.indexOf("/document/d/")>0)
	{
		try
		{
			l=tablink.indexOf("/document/d/");
			var docid=tablink.substr(l+12).split("/")[0];
			var tabsrc="https://clicktopost.appspot.com/Clicktopost.html?docid="+docid;
			chrome.tabs.create({url:tabsrc});
			
			
			
		}
		catch(err)
		{
			alert("Could not get google document id");
		}

	}
	else
	{
		alert("Could not get google document id");
	}
	

});	
	
	
</script>
